{include file="public/header" /}
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">轮播图</a></li>
        <li><a href="{:url('banner/add',array('action' => 'add'))}">添加轮播图</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" method="post" action="{:url('banner/index')}">
        <div class="well form-inline margin-top-20">
            名称:
            <input type="text" class="form-control" name="name" style="width: 200px;"
                   value="{$params['name']|default=''}" placeholder="请输入名称">　
            状态:
            <select class="form-control" name="status" style="width: 140px;">
                <option value=''>全部</option>
                <option value='1' {if condition="$params['status'] eq '1'"} selected="selected" {/if} >启用</option>
                <option value='0' {if condition="$params['status'] eq '0'"} selected="selected" {/if} >禁用</option>
            </select>　
            <input type="submit" class="btn btn-primary" value="搜索"/>　
            <a class="btn btn-danger" href="{:url('banner/index')}">清空</a>
        </div>

        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>跳转url</th>
                <th>图片</th>
                <th>状态</th>
                <th>排序</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            {foreach name="list" item="vo"}
            <tr>
                <td>{$vo.id}</td>
                <td>{$vo.name}</td>
                <td>{$vo.url}</td>
                <td>
                    {empty name="$vo['image']"}
                    <img src="/assets/images/default-thumbnail.png" width="50"/>
                    {else /}
                    <img src="{$vo.image}" width="50"/>
                    {/empty}
                </td>
                <td>
                    {if condition="$vo['status'] eq '1'"}
                        已启用
                    {else /}
                        已禁用
                    {/if}
                </td>
                <td>
                    <input type="text" value="{$vo.sort}" class="input-order valid js-sort" data-id="{$vo.id}"/>
                </td>
                <td>{$vo.createTime}</td>
                <td>
                    <a href="{:url('banner/edit',array('action'=>'edit','id'=>$vo['id']))}">编辑</a>
                </td>
            </tr>
            {/foreach}
        </table>
    </form>
</div>
<script src="/static/admin/js/admin.js"></script>
<script type="text/javascript">
    $(".js-sort").blur(function () {
        var sort = this.value;
        var id = $(this).data('id');
        $.post("{:url('article/updateArticleSort')}", {id:id,sort:sort}, function (res) {
            if(res.errorCode === 200){
                layer.confirm(res.message, {
                    btn:['确认','取消'],
                    success:function(){
                        this.enterEsc = function (event) {
                            if (event.keyCode === 13) {
                                $(".layui-layer-btn0").click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.enterEsc);

                        $(".layui-layer-btn0").on("click",function() {
                            window.location.reload();
                            return false
                        })
                    },
                    end:function(){
                        $(document).off('keydown',this.enterEsc);
                    }
                });
            }else{
                layer.alert(res.message, {
                    title: '提示',
                    icon: 2
                });
            }
        },'json');
        return false;
    });
</script>
</body>
</html>